package suanfa;

public class RandomTest4 {

    public static void main(String[] args) {
        int[] nums = new int[2];
        int times = 100000;
        for (int i = 0; i < times; i++) {
            nums[f()]++;
        }
        for (int i = 0; i < nums.length; i++) {
            System.out.println(i + "出现了" + nums[i] + "次");
        }
    }

    private static int f() {
        int val1,val2;
        do {
            val1 = p84r016r1();
        } while ((val2 =p84r016r1()) == val1);
        //这里返回val1或val2都不影响结果的概率
        return val2;
    }

    private static int p84r016r1() {
        return Math.random() < 0.84d ? 0 : 1;
    }

}
